package com.decent.manager.system.dao.provider;

import cn.hutool.core.text.CharSequenceUtil;
import com.decent.manager.system.dto.SystemMenuDTO;

import java.util.Map;
import java.util.Objects;

/**
 * 系统资源sql管理
 *
 * @author wangyan
 **/
public class SystemMenuDaoProvider {
    /**
     * 列表查询
     *
     * @param params 查询条件
     * @return 结果
     */
    public String list(Map<String, SystemMenuDTO> params) {
        SystemMenuDTO dto = params.get("dto");
        StringBuilder sql = new StringBuilder(64);
        sql.append("select * from system_menu t1 where t1.status = 'NORMAL' ");
        if (CharSequenceUtil.isNotBlank(dto.getMenuName())) {
            sql.append(" and instr(t1.menu_name,#{dto.menuName}) > 0 ");
        }
        if (Objects.nonNull(dto.getId())) {
            sql.append(" and find_in_set('[${dto.id}]',pids) > 0 ");
        }
        sql.append(" order by menu_sort asc ");
        return sql.toString();
    }
}
